Ext.onReady(function(){
	var tody = new Date().format("Y-m-d");//取得今天日期
	var provinceStr = "";
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.apply(Ext.form.VTypes, {
    password : function(val, field) {
        if (field.initialPassField) {
            var pwd = Ext.getCmp(field.initialPassField);
            return (val == pwd.getValue());
        }
        return true;
    },
    passwordText : '密码不匹配'
});
	var regPanel = new Ext.FormPanel({
		bodyStyle:'padding:25px 50px 0',
		baseCls:"x-plain",
		buttonAlign:"center",
		labelWidth:80,
		autoScroll:false,
		anchor:"100%",
		defaults:{xtype:"textfield",width:160},
		items:[{
			 fieldLabel: '用户名',
             name: 'email',
             id:'email',
             allowBlank:false,
             blankText:"用户名是必填项项", 
             vtype:'email'
		},{
			xtype:"datefield",
			format:"Y-m-d",
			fieldLabel:"出生日期",
			allowBlank:false,
			blankText:"出生日期是必填项", 
			editable:true,
			name:"birthday",
			id:'birthday',
			minValue:'1949-10-01',
			maxValue:tody
		},{
			xtype:"combo",
			fieldLabel:"性别",
			mode:"local",
			id:"sex",
			editable:false,
			displayField:"sex",
			triggerAction:"all",
			value:"男",
			store:new Ext.data.SimpleStore({
						fields:["sex"],
						data:[['男'],['女']]					})
		},{
			xtype:"combo",
			fieldLabel:"籍贯",
			mode:"remote",
			editable:false,
			loadingText:"请稍等...",
			id:"province",
			allowBlank:false,
			blankText:"籍贯是必选项", 
			displayField:"name",
			triggerAction:"all",
			emptyText:"请选择省份",
			store:new Ext.data.JsonStore({
						url:'json/json-array-of-province.json',
						autoLoad:true,
						root:"province",
						fields:["name","code"]						
					})
		},{
			xtype:"combo",
			fieldLabel:"密保问题",
			allowBlank:false,
			editable:false,
			blankText:"密保问题是必选项", 
			mode:"local",
			id:"safequestion",
			displayField:"safequestion",
			triggerAction:"all",
			emptyText:"请选择密码保护问题",
			store:new Ext.data.SimpleStore({
						fields:["safequestion"],			
						data:[['您就读的第一所学校的名称?'],['您第一次亲吻的对象是谁'],['少年时代心目中的英雄是谁?'],['您最喜欢的休闲运动是什么?'],['您最喜欢哪支运动队?'],['您最喜欢的运动员是谁?'],['高中的校训是什么?'],['您的生日是哪天的?']]
					})
		},
		  {
			 fieldLabel: '密码保护答案',
			 allowBlank:false,
			 blankText:"密码答案是必选项", 
             name: 'saferesult',
             id:'saferesult',
             allowBlank:false,
             minLength:4,
             maxLength:30
		},{
	        fieldLabel: '密码',
	        inputType:"password",
	        allowBlank:false,
	        blankText:"密码是必填项",
	        name:'passwd',
	        id: 'passwd'
      },{
	        fieldLabel: '密码确认',
	        inputType:"password",
	         allowBlank:false,
	        blankText:"密码确认是必填项",
	        id:"passcfrm",
	        name: 'passcfrm',
	        vtype: 'password',
	        initialPassField: 'passwd'
      }			
		],
		buttons:[{
			text:"注册",
			handler:register
			
		},{
			text:'重置',
			type:"reset",
			handler:formreset
		}]
	});
	var win = new Ext.Window({
		title:"用户注册",
		width:400,
		height:350,
		closable:false,
		modal:true,
		plain:true,
		items:regPanel
	});
	win.show();
	function register(){
		var v_email = jQuery("#email").val();
		var v_birthday =jQuery("#birthday").val();
		var v_sex = jQuery("#sex").val()=='男'?1:0;
		var v_address =jQuery("#province").val();
		var v_safequestion = jQuery("#safequestion").val();
		var v_saferesult = jQuery("#saferesult").val();
		var v_passwd = jQuery("#passwd").val();
		alert(v_email + "生日:" + v_birthday + "性别" + v_sex + "地址" + v_address + "问题" + v_safequestion + "答案" + v_saferesult + "密码" + v_passwd);
		if(regPanel.getForm().isValid()){
			Ext.Ajax.request({
				url:"register.action",
				success:regSuc,
				method:"post",
				 params:{
						"user.email":v_email,
						"user.passwd":v_passwd,
						"user.birthday":v_birthday,
						"user.safeQuestion":v_safequestion,
						"user.safeResult":v_saferesult,
						"user.address":v_address,
						"user.sex":v_sex
				}
			});
		}else{
		Ext.Msg.alert("提示","请检查输入项");
		}
	}
	function formreset(){
		regPanel.getForm().reset();
	}
	function regSuc(obj){
		if(obj.responseText == "fail"){
			Ext.Msg.alert("提示","注册失败!");
		}
		if(obj.responseText == "success"){			
		Ext.Msg.alert("提示","恭喜你注册成功!现在就去登录吧",function(){
			location.href="login.jsp";
		})
		}
	}
});
